const{
  formatPrice
  }=require("../../utils/util");
  import{
  getLoginCode,
  getUserInfo
  }from'../../utils/other'
  import{
  parseTime,
  formatParkingTime
  }from'../../utils/util'
  const app=getApp()
  // const 
  import{
  login
  }from'../../api/user';
  import{
  listVehicle
  }from'../../api/home.js';
  import{
    listActivity
  }from'../../api/activity'
// import { from } from 'form-data';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    background: ['demo-text-1', 'demo-text-2', 'demo-text-3'],
    indicatorDots: true,
    vertical: false,
    autoplay: false,
    interval: 2000,
    duration: 500,
    text: '车辆已入场通知   2020-09-08 19:00:08',
    tccc: "商业中心",
    rcsj: "2021-07-15 17:28:50",
    ytcc: "100小时",
    active: 0,
    nrbt: "这是标题",
    listVehicle: null,
    nrzw: "这里是活动内容正文这里是活动内容正文这里是活动内容正文这里是活动内容正文这里是活动内容正文这里是活动内容正文这里是活动内容正文",
    imgg: "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg1.gtimg.com%2Fauto%2Fpics%2Fhv1%2F246%2F190%2F1582%2F102918246.jpg&refer=http%3A%2F%2Fimg1.gtimg.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1626011463&t=0fcff9e22e1277c3f3a623ca51c0d1a4",
    onChange(event) {
      // event.detail 的值为当前选中项的索引
      this.setData({
        active: event.detail
      });
    },
    listVehicle: [{
      "vehicleNumber": "粤A·123456",
      "parkName": "领汇创展商业中心",
      "parkDate": "2021-09-09 09:00:08",
      "stopDate": "3小时15分",
    }]
  },
  gotoActivity: function () {
    wx.navigateTo({
      url: '/pages/home/active/activeDetailPage',
    })
  },
  gotoInforMation: function () {
    wx.navigateTo({
      url: '/pages/home/active/newsConsult',
    })
  },
  gotoMineCar: function () {
    wx.navigateTo({
      url: '/pages/vehicle/demo/demo',
      // url: '/pages/details/details',
    })
  },
  gotoCarPay: function () {
    wx.navigateTo({
      url: '/pages/pay/pay',
    })
  },
  gotoAdvert: function () {
    wx.navigateTo({
      url: '/pages/message/advert/index',
    })
  },
  // 跳转 
  hddj: function () {
    wx.navigateTo({
      url: '/pages/me/meInfo/meInfo',
    })
  },

  lookMoreActive: function () {
    wx.navigateTo({
      url: '/pages/message/active/index',
    })
  },
  lookMoreNew: function () {
    wx.navigateTo({
      url: '/pages/message/news/index',
    })
  },
  // other
  changeIndicatorDots() {
    this.setData({
      indicatorDots: !this.data.indicatorDots
    })
  },

  changeAutoplay() {
    this.setData({
      autoplay: !this.data.autoplay
    })
  },

  intervalChange(e) {
    this.setData({
      interval: e.detail.value
    })
  },

  durationChange(e) {
    this.setData({
      duration: e.detail.value
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  async onLoad(options) {
    try {
      const code = (await getLoginCode()).code
      app.globalData.userInfo = (await getUserInfo()).userInfo
      // 调了登陆接口
      const token = (await login({
        code
      }))
      app.globalData.isLogin = true
      app.globalData.token = token
      this.setData({
        // 调了车辆列表的接口
        listVehicle: (await listVehicle()).map(item => {
          item.parkDate = parseTime(item.parkDate)
          item.stopDate = formatParkingTime(item.stopDate)
          return item
        })
      })
    } catch {
      app.globalData.isLogin = false
    }
  },
  /**
   *  活动
   */
  // export function login(data) {
  //   wx.request({
  //     url: "/pages/",

  //     data: {
  //     }
  //   })
  // }


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    if (typeof this.getTabBar === 'function' && this.getTabBar()) {
      this.getTabBar().setData({
        selected: 0 //数字是当前页面在tabbar的索引,如我的查询页索引是2，因此这边为2，同理首页就为0，审批页面为1
      })
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {
      title: 'swiper',
      path: 'page/component/pages/swiper/swiper'
    }
  }
})